package leetcode;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2021-12-05 19:17
 **/
public class LeetCode367 {

    //二分查找
    public boolean isPerfectSquare(int num) {
        long low = 0;
        long high = num;
        while (low <= high) {
            long mid = low + high >> 1;
            long multi = mid * mid;
            if (multi == num) {
                return true;
            } else if (multi < num) {
                low = mid + 1;
            } else {
                high = mid - 1;
            }
        }
        return false;
    }

}
